#!/bin/sh
#
# Copyright (c) 2008 Bruce M. Simpson.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD$
#
# Convenience function for CDROM and DVD devices.
#
# There is a hook over in nanobsd.sh which allows you to call into
# this function simply with a line like:
#
#	CdromDevice CD [sizeMB]
#
# This file will then set NANO_MEDIASIZE, NANO_HEADS and NANO_SECTS for you.
# NANO_HEADS and NANO_SECTS generally have no meaning for UDF and ISO,
# however, so they are set to default values.
# NANO_MEDIASIZE is currently always expressed in terms of 512-byte sectors,
# CDROM devices have a 2048 byte sector size.
# One head, one spiral track.
#

sub_CdromDevice () {
	a1=`echo $1 | tr '[:upper:]' '[:lower:]'`
	case $a1 in
	cd)
		if [ $# -eq 2 ]; then
		    NANO_MEDIASIZE=$(( $2 * 1024 * 1024 / 512 ))
		else
		    # default 650MB ISO image
		    NANO_MEDIASIZE=1332000
		fi
		NANO_HEADS=1
		NANO_SECTS=${NANO_MEDIASIZE}
		NANO_CDROM=true
		;;
	*)
		echo "Unknown CDROM device type"
		exit 2
		;;
	esac

	# Set NANO_DRIVE in case the user forgot to set it,
	# or set it to something which is not a CDROM/DVD device.
	NANO_DRIVE=${NANO_DRIVE:-"acd0"}
	case $NANO_DRIVE in
	acd*|cd*)
		;;
	*)
		echo "Forcing NANO_DRIVE to acd0".
		NANO_DRIVE=acd0
		;;
	esac
}
